package com.my.main.component.interceptor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;


@Configuration
public class CommonInterceptorConfiguration extends WebMvcConfigurerAdapter {

    @Bean
    public ApiPermissionInterceptor apiPermissionInterceptor() {
        return new ApiPermissionInterceptor();
    }
//    @Bean
//    public DistributedLockAnnotationInterceptor distributedLockAnnotationInterceptor() {
//        return new DistributedLockAnnotationInterceptor();
//    }
    @Bean
    public ContextInfoInterceptor contextInfoInterceptor() {
        return new ContextInfoInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册自定义拦截器，添加拦截路径和排除拦截路径
        registry.addInterceptor(contextInfoInterceptor()).addPathPatterns("/**").excludePathPatterns("", "");
        registry.addInterceptor(apiPermissionInterceptor()).addPathPatterns("/**").excludePathPatterns("", "");
//        registry.addInterceptor(distributedLockAnnotationInterceptor()).addPathPatterns("/**").excludePathPatterns("", "");
        super.addInterceptors(registry);
    }
}

